// Email cloaker v1.0
// Date 01:38 14/12/2016
// By Ben a.k.a DreamVB

#include <string>
#include <iostream>

using namespace std;
using std::cout;
using std::endl;

string EncodeString(string src){
	string buffer = "";
	char sNum[10];
	int i = src.length();
	int j = 0;
	//Converts a string to HTML decimal values.
	//So the string AB whould return &#65;&#66;
	while (j < i){
		//Convert int to char
		itoa((int)src[j], sNum, 10);
		buffer.append("&#");
		buffer.append(sNum);
		buffer.append(";");
		//INC counter
		j++;
	}
	return buffer;
}

int main(int argc, char *argv[]){
	char sTitle[80];
	char sAddr[80];

	//Check program params
	if (argc != 3){
		cout << "Usage: <email-address><email-title>\n";
		cout << "  Example " << argv[0] << " you@yourdomain.com \"Contact Me\"\n";
		exit(1);
	}

	//Copy argv1 and argv2 into sTitle and sAddr
	strcpy(sAddr, argv[1]);
	strcpy(sTitle, argv[2]);

	//Create email link
	cout << "<!--Now just copy & paste the lines below into your HTML editor-->\n\n";
	cout << "<a href='";
	cout << EncodeString("mailto:");
	cout << EncodeString(sAddr);
	cout << "'>";
	//Create title for email
	cout << EncodeString(sTitle);
	cout << "</a>\n";

	//Clear up after our selfs.
	memset(sTitle, 0, sizeof(sTitle));
	memset(sAddr, 0, sizeof(sAddr));

	return EXIT_SUCCESS;
}